import asyncio
from typing import Dict

# 模拟缓存价格
ticker_cache: Dict[str, float] = {
    "BTCUSDT": 30200.0,
    "ETHUSDT": 1900.0,
}

async def websocket_endpoint():
    try:
        while True:
            print("当前价格缓存：", ticker_cache)
            await asyncio.sleep(1)
    except asyncio.CancelledError:
        print("任务取消")
    except Exception as e:
        print(f"[WebSocket Error] {e}")

async def main():
    task = asyncio.create_task(websocket_endpoint())
    await asyncio.sleep(10)  # 模拟运行 10 秒后退出
    task.cancel()
    await asyncio.gather(task, return_exceptions=True)

if __name__ == "__main__":
    asyncio.run(main())